<%@ page contentType="text/html; charset=UTF-8" language="java"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
</head>
<body>
<!-- Table -->
	<table id="datagrid_sysmenu" 
		   class="easyui-datagrid"
		   url="sysmenu/findSysMenus.jhtml" 
		   toolbar="#datagrid_toolbar_sysmenu" 
		   pagination="true" 
		   rownumbers="true" 
		   fitColumns="false"  
		   fit="true" 
		   singleSelect="true"  
		   border="false">
		<thead>
			<tr>
				<th field="id" hidden="true" width="100">id</th>
				<th field="text" sortable="false" width="100">菜单名</th>
				<th field="url" sortable="false" width="100">连接地址</th>
				<th field="sort" sortable="false" width="100">排序</th>
				<th field="ptext" sortable="false" width="100">父菜单</th>
				<th field="pid" hidden="true" width="100">父菜单id</th>
			</tr>
		</thead>
	</table>
	<div id="datagrid_toolbar_sysmenu">
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add" plain="true" onclick="add_sysmenu()">新增</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="edit_sysmenu()">编辑</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-remove" plain="true" onclick="del_sysmenu()">删除</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-so" plain="true" onclick="search_sysmenu()">查询</a>
	</div>
	<script type="text/javascript">
		$('#datagrid_sysmenu').datagrid({ 			
		    onDblClickRow : function(rowIndex, rowData){ edit_sysmenu(); }
		});
	</script>
<!-- Compile -->
	<div id="dialog_compile_sysmenu" 
		 class="easyui-dialog" 		
		 resizable="true" 
		 maximizable="true" 
		 closed="true" 
		 buttons="#dialog_compile_buttons_sysmenu" 
		 data-options="modal:true,iconCls:'icon-save'"
		 style="width:400px;height:280px;padding:10px 20px">
		<form id="frm_compile_sysmenu" method="post" novalidate>
			<input id="id_sysmenu" name="id" type="hidden" >
			<table style="width: 100%">
				<tr>
					<td width="100">菜单名:</td>
					<td>
						<input id="text_sysmenu_compile" name="text" 
							   class="easyui-validatebox" required="true" maxlength="128"
						></input>
					</td>
				</tr>
				<tr>
					<td width="100">连接地址:</td>
					<td>
						<input id="url_sysmenu_compile" name="url"  maxlength="128" 
						></input>
					</td>
				</tr>				
				<tr>
					<td width="100">排序:</td>
					<td>
						 <input id="sort_sysmenu_compile" name="sort" 
						 	    class="easyui-numberbox" data-options="required:false"
						 	    maxlength="11"
						 ></input>
					</td>
				</tr>
				<tr>
					<td width="100">父菜单:</td>
					<td>						
						<input id="pid_sysmenu_compile" name="pid" 
							   class="easyui-combotree" 
							   data-options="url:'sysmenu/getSysMenu4Async.jhtml',required:false,multiple:false" 
					    ></input>
					</td>
				</tr>
			</table>
		</form>
	</div>	
	<div id="dialog_compile_buttons_sysmenu">
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="action_sysmenu()">保存</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dialog_compile_sysmenu').dialog('close')">取消</a>
	</div>
<!-- Search -->
	<div id="dialog_search_sysmenu" 
			class="easyui-dialog"			
			resizable="true" 
			maximizable="true" 
			closed="true" 			
			buttons="#dialog_buttons_search_sysmenu" 
			data-options="modal:true,iconCls:'icon-search'"
			style="width:400px;height:280px;padding:10px 20px">
		<form id="frm_search_sysmenu" method="post" novalidate>
			<input id="id_search_sysmenu" name="id" type="hidden" >
			<table style="width: 100%">
				<tr>
					<td width="100">菜单名:</td>
					<td>
						<input id="text_sysmenu_search" name="text" maxlength="128"></input>
					</td>
				</tr>	
				<tr>
					<td width="100">父菜单:</td>
					<td>
						<input id="pid_sysmenu_search" name="pid" 
							   class="easyui-combotree" 
							   data-options="url:'sysmenu/getSysMenu4Async.jhtml',editable:true,multiple:false" 
					    ></input>
					</td>
				</tr>
			</table>			
		</form>
	</div>	
	<div id="dialog_buttons_search_sysmenu">
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-ok" onclick="action_sysmenu()">查询</a>
		<a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-cancel" onclick="javascript:$('#dialog_search_sysmenu').dialog('close')">取消</a>
	</div>
<!-- Event  -->
	<script type="text/javascript">
        var url_sysmenu;
        var action_type_sysmenu;
        function add_sysmenu(){
        	action_type_sysmenu="create";
        	$('#dialog_compile_sysmenu').dialog('open').dialog('setTitle','新增');
            $('#frm_compile_sysmenu').form('clear');
            url_sysmenu = 'sysmenu/create.jhtml';
        }
        function edit_sysmenu(){
        	action_type_sysmenu="update";
        	var row = $('#datagrid_sysmenu').datagrid('getSelected');
            if (row){
                $('#dialog_compile_sysmenu').dialog('open').dialog('setTitle','编辑');
                $('#frm_compile_sysmenu').form('load',row);
                url_sysmenu = 'sysmenu/update.jhtml';
            }
        }
        function search_sysmenu(){
        	action_type_sysmenu="search";
        	$('#dialog_search_sysmenu').dialog('open').dialog('setTitle','查询');
        }
        function action_sysmenu(){
        	if(action_type_sysmenu == "search"){
        		$('#datagrid_sysmenu').datagrid('load',getFormJson($('#frm_search_sysmenu')));	        	
    	        $('#dialog_search_sysmenu').dialog('close');
        	}else{        		
        		$('#frm_compile_sysmenu').form('submit',{
	                url: url_sysmenu,
	                onSubmit: function(){
	                    return $(this).form('validate');
	                },
	                success: function(result){
	                	var result = eval('('+result+')');                    
	                    if (result.errorMsg){
	                        $.messager.show({
	                            title: 'Error',
	                            msg: result.errorMsg
	                        });
	                    } else {
	                        $('#dialog_compile_sysmenu').dialog('close');
	                        $('#datagrid_sysmenu').datagrid('reload');
	                    }
	                }
	            });
        	}        	
	    }        
        function del_sysmenu(){
            var row = $('#datagrid_sysmenu').datagrid('getSelected');
            if (row){
                $.messager.confirm('Confirm','确定要删除吗?',function(r){
                    if (r){                    	
                        $.post('sysmenu/delete.jhtml',{id:row.id},function(result){                        	
                        	if (result.success){
                                $('#datagrid_sysmenu').datagrid('reload');
                            } else {
                                $.messager.show({
                                    title: 'Error',
                                    msg: result.errorMsg
                                });
                            }
                        },'json');
                    }
                });
            }
        }
    </script>	    
</body>
</html>